import pygame
from setting import Setting
from pygame.sprite import Sprite

class Bullet(Sprite):
    def __init__(self , ai_game):
        super().__init__()
        #初始化子弹并设置其位置
        self.screen=ai_game.screen

        self.setting=Setting()
        self.plane_rect = ai_game.plane.rect
        #加载子弹图片并且获取其外接矩形
        self.image=pygame.image.load('"images/bullet1.png"').convert_alpha()
        self.rect=self.image.get_rect()
        #设置其在飞机顶端发射
        self.rect.midbottom=self.plane_rect.midtop
        self.speed=12
        self.active = True
        self.mask=pygame.from_surface(self.image)

        #子弹的移动
    def update(self):
        self.rect.top-=self.speed
        if self.rect.top<0:
            self.active=False
    # def blitme(self):
    #     self.screen.blit(self.image,self.rect)
    def resert(self):
        self.rect.midbottom=self.plane_rect.midtop
        self.active=True
class Bullet_1(Sprite):
    def __init__(self , ai_game):
        super().__init__()
        #初始化子弹并设置其位置
        self.screen=ai_game.screen

        self.setting=Setting()
        self.plane_rect = ai_game.plane.rect
        #加载子弹图片并且获取其外接矩形
        self.image=pygame.image.load('"images/bullet2.png"').convert_alpha()
        self.rect=self.image.get_rect()
        #设置其在飞机顶端发射
        self.rect.midbottom=self.plane_rect.midtop
        self.speed=12
        self.active = True
        self.mask=pygame.from_surface(self.image)

        #子弹的移动
    def update(self):
        self.rect.top-=self.speed
        if self.rect.top<0:
            self.active=False

    def resert(self):
        self.rect.midbottom=self.plane_rect.midtop
        self.active=True